package com.os;

/**
 * @author rkc
 * @date 2022/9/3 10:58
 */
public class OS {

    private final static String osName = System.getProperty("os.name").toLowerCase();
    private final static OS os = new OS();

    private Platform platform;

    private OS() { }

    public static boolean isLinux() {
        return osName.contains("linux");
    }

    public static boolean isMacOS() {
        return osName.contains("mac") && osName.indexOf("os") > 0 && !osName.contains("x");
    }

    public static boolean isMacOSX() {
        return osName.contains("mac") && osName.indexOf("os") > 0 && osName.indexOf("x") > 0;
    }

    public static boolean isWindows() {
        return osName.contains("windows");
    }

    public static boolean isOS2() {
        return osName.contains("os/2");
    }

    public static boolean isSolaris() {
        return osName.contains("solaris");
    }

    public static boolean isSunOS() {
        return osName.contains("sunos");
    }

    public static boolean isMPEiX() {
        return osName.contains("mpe/ix");
    }

    public static boolean isHPUX() {
        return osName.contains("hp-ux");
    }

    public static boolean isAix() {
        return osName.contains("aix");
    }

    public static boolean isOS390() {
        return osName.contains("os/390");
    }

    public static boolean isFreeBSD() {
        return osName.contains("freebsd");
    }

    public static boolean isIrix() {
        return osName.contains("irix");
    }

    public static boolean isDigitalUnix() {
        return osName.contains("digital") && osName.indexOf("unix") > 0;
    }

    public static boolean isNetWare() {
        return osName.contains("netware");
    }

    public static boolean isOSF1() {
        return osName.contains("osf1");
    }

    public static boolean isOpenVMS() {
        return osName.contains("openvms");
    }

    public static Platform getPlatform() {
        if (isAix()) {
            os.platform = Platform.AIX;
        } else if (isDigitalUnix()) {
            os.platform = Platform.Digital_Unix;
        } else if (isFreeBSD()) {
            os.platform = Platform.FreeBSD;
        } else if (isHPUX()) {
            os.platform = Platform.HP_UX;
        } else if (isIrix()) {
            os.platform = Platform.Irix;
        } else if (isLinux()) {
            os.platform = Platform.Linux;
        } else if (isMacOS()) {
            os.platform = Platform.Mac_OS;
        } else if (isMacOSX()) {
            os.platform = Platform.Mac_OS_X;
        } else if (isMPEiX()) {
            os.platform = Platform.MPEiX;
        } else if (isNetWare()) {
            os.platform = Platform.NetWare_411;
        } else if (isOpenVMS()) {
            os.platform = Platform.OpenVMS;
        } else if (isOS2()) {
            os.platform = Platform.OS2;
        } else if (isOS390()) {
            os.platform = Platform.OS390;
        } else if (isOSF1()) {
            os.platform = Platform.OSF1;
        } else if (isSolaris()) {
            os.platform = Platform.Solaris;
        } else if (isSunOS()) {
            os.platform = Platform.SunOS;
        } else if (isWindows()) {
            os.platform = Platform.Windows;
        } else {
            os.platform = Platform.Others;
        }
        return os.platform;
    }

    public static void main(String[] args) {
        System.out.println(getPlatform());
    }
}
